<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>打印li的索引</title>
</head>
<body>
<ul>
    <li>0</li>
    <li>1</li>
    <li>2</li>
    <li>3</li>
    <li>4</li>
</ul>
<script>
    var all = document.querySelectorAll('li');
    for (var i = 0; i < all.length; i++) {
        (function (j) {
            all[j].onclick = function () {
                console.log('la');
            }
        })(i)
    }
    console.log(i);
    console.log(all[0].onclick === all[1].onclick);
</script>
</body>
</html>
